#ifndef DBDATA_H
#define DBDATA_H

#pragma once

#include <QSqlDatabase>
#include "dbtype.h"
// #include "model/modelbasicfishingarea.h"
// #include "model/modellayer.h"
#include <QSharedPointer>
#include <QVector>
#include "model/modelriskarea.h"

namespace ns_yht
{

#define DBDATA (DbData::instance())

    class DbData
    {
    public:
        DbData();
        DbData(const QString &host, const QString &database, const QString &uid, const QString &pwd);
        ~DbData();

        // void connect(const QString &host, const QString &database, const QString &uid, const QString &pwd);

        static DbData *instance();

        QSqlDatabase &getDb();
        bool isOk() const;

        DBType getDbType() const;

        // bool getFishingArea(int type, QVector<ModelBasicFishingArea> &areaList);
        // bool saveFishingArea(int type, const QVector<ModelBasicFishingArea> &areaList);

        // bool getLayerList(QVector<QSharedPointer<ModelLayer>> &layerList, int stype = 0);

        QString getCountry(int id);
        bool getCountryList(QStringList &sList);

        bool getShipInfo(qint64 mmsi, QString &enName, QString &cnName, QString &nationality, int &typeId);
        bool getShipList(const QString &key, QVector<QPair<quint64, QString>> &shipList);

        bool getRiskArea(QVector<ModelRiskArea> &areaList);
        bool saveRiskArea(const QVector<ModelRiskArea> &areaList);

    private:
        bool checkTFishingArea();
        bool checkTRiskArea();

        QSqlDatabase m_dbData;

        DBType m_dbType;

        static DbData *g_dbData;
    };

} // namespace ns_yht
#endif // DBAPP_H
